home *** CD-ROM | disk | FTP | other *** search
- #include <graphics libraries.h>
- #include <graphics toolbox.h>
- #include <offscreen library.h>
- #include <qd library.h>
- #include <graphics debugging.h>
- #include "TileProtos.h"
- #include "TileConstants.h"
-
- #define kGiveMeValidation false /* set to TRUE, for run-time validation */
- #define kDebugging true /* set to TRUE, for error & notice posting. This
- functionality is only available with the "debugging"
- Secret Graphics init. */
-
-
-
- // Globals only needed in this file
- WindowRecord gWindRecord;
- Rect gWindowQDRect = {50, 50, 306, 306};
-
-
- // Other app globals
- extern MenuHandle gAppMenuHandle;
- extern WindowPtr gWindPtr;
- extern gxGraphicsClient gGraphicsClient;
-
- //---------------------------------------
- // Tile globals
- extern gxPoint gOrigin;
- extern gxColorSet gColors;
- extern offscreen gOffScreen;
- extern gxShape gTileShape, // The contours that fill the unit cell (transforms of gDragger.snake1)
- gGridShape, // A rectangle filled with the pattern
- gBGShape; // A rectangle filled with the background color
-
- extern dragger gDragger; // A record containing manipulable contour(s)
- extern gxPatternRecord gPattern;
-
- extern Boolean gContRedraw, gShowVectors; // State Booleans
- extern long gSymmetry; // the currently chosen symmetry group
- extern gxViewPort gViewPort;
-
- // Proto for Gestalt function to check for GX
- Boolean QuickDrawGXInstalled(void);
-
- Boolean TileInit(void)
- {
- unsigned long seed;
- MenuHandle mhndl;
-
- // Offscreen stuff
- CTabHandle standardClut;
- gxBitmap offMap;
- gxShape offBits;
-
- // Check for GX
- if(QuickDrawGXInstalled() == false)
- {
- SysBeep(10);
- ExitToShell();
- }
-
- /**
- Define the graphics heap size. If you do not make this call, graphics will
- create this heap automatically. How? It will create a heap which is a % of your
- application's ideal memory foot print. this call allows you to explicity define
- the ammount of memory used by the graphics system for it's graphics objects heap.
- **/
- gGraphicsClient = GXNewGraphicsClient(nil, 0L, 0L);
-
- /**
- Set kDebugging to TRUE, if you want to have graphics library errors & notices posted. This
- functionality will only work with the "debugging" Secret Graphics init. If this
- init is not installed, these functions will not work.
- **/
- if (kDebugging) {
- SetGraphicsLibraryErrors ();
- SetGraphicsLibraryNotices();
- }
-
- /**
- Set "kgiveMeValidation" to TRUE, if you want run-time checking. The drawing will get very
- SLOW due to all of the internal checking. You can set the validation to a higher level,
- see Chapter 3 for details.
- **/
- if ( kGiveMeValidation ) GXSetValidation(gxPublicValidation);
-
- /** initialize the new graphics environment **/
- GXEnterGraphics();
-
- // Init the common color library
- InitCommonColors();
-
- // Create the window.
- gWindPtr = NewWindow( &gWindRecord,
- &gWindowQDRect,
- "\pDrag Colored Shapes",
- true,
- documentProc,
- (WindowPtr)(-1),
- true, /* has a close box */
- 0L );
- SetPort(gWindPtr);
- ClipRect(&gWindPtr->portRect);
- EraseRect(&gWindPtr->portRect);
-
- gViewPort = GXNewWindowViewPort(gWindPtr);
- GXIgnoreGraphicsNotice(transform_already_set);
- SetDefaultViewPort(gViewPort);
- GXPopGraphicsNotice();
-
- // Reset random number generator
- GetDateTime(&seed);
- qd.randSeed = seed;
-
- /* Set up a color space with the default 8-bit colors for our offscreen */
- standardClut = GetCTable(72);
- gColors = CTableToColorSet( standardClut );
- DisposCTable(standardClut);
-
- /* Set up the off-screen bitmap */
- offMap.image = nil;
- offMap.width = gWindPtr->portRect.right - gWindPtr->portRect.left;
- offMap.height = gWindPtr->portRect.bottom - gWindPtr->portRect.top;
- offMap.rowBytes = 0;
- offMap.pixelSize = 8;
- offMap.space = gxIndexedSpace;
- offMap.set = gColors;
- offMap.profile = nil;
- offBits = GXNewBitmap(&offMap, &gOrigin);
- CreateOffscreen(&gOffScreen, offBits);
- GXDisposeShape(offBits);
-
- // set up background shape with the right color
- gBGShape = GetWindowBoundsShape(gWindPtr);
- SetShapeCommonColor(gBGShape, kBGColor);
-
- // Set up our patterned shape (DefaultTileAndPattern will actually add the pattern to it)
- gGridShape = GXCopyToShape(nil, gBGShape);
- SetShapeCommonColor(gGridShape, kGridColor);
-
- // Set them both to draw offscreen
- GXSetShapeTransform(gBGShape, gOffScreen.xform);
- GXSetShapeTransform(gGridShape, gOffScreen.xform);
-
- // Make the tile shape
- gTileShape = GXNewShape(gxPolygonType);
- GXSetShapeFill(gTileShape, gxOpenFrameFill);
-
- // Set up the dragger. It has one open polygon
- gDragger.snake1 = GXNewShape(gxPolygonType);
- GXSetShapeFill(gDragger.snake1, gxOpenFrameFill);
- SetShapeCommonColor(gDragger.snake1, kDragColor);
- GXSetShapePen(gDragger.snake1, ff(3));
-
- // Set up the initial pattern
- gPattern.attributes = gxNoAttributes;
- gPattern.pattern = gTileShape;
-
- // Set up all the initial geometry
- DefaultTileAndPattern();
-
- // Add the "Tile" menu
- mhndl = GetMenu(kTileMenuID);
- if(mhndl == nil)
- return false;
-
- (*mhndl)->menuID = kTileMenuID;
- InsertMenu(mhndl, 0);
- gAppMenuHandle = mhndl;
-
- /* Update the menu bar */
- DrawMenuBar();
-
- return(true);
- }
-
- void TileQuit(void)
- {
- // Tile stuff
- DisposeOffscreen(&gOffScreen);
- GXDisposeColorSet(gColors);
- GXDisposeShape(gTileShape);
- GXDisposeShape(gGridShape);
- GXDisposeShape(gBGShape);
- DisposeDragger();
- DisposeOpShapes();
-
- GXDisposeViewPort(GXGetWindowViewPort(gWindPtr));
- if(gWindPtr != nil)
- CloseWindow(gWindPtr);
-
- DisposeCommonColors();
- }
-
- Boolean QuickDrawGXInstalled(void)
- {
- long theFeatureInQuestion;
-
- // Check for GX
- if (Gestalt('grfx', &theFeatureInQuestion) == noErr)
- return(true);
- return(false);
- }
-
-
-
-